package gamehandlers;

import gui.GameFrame;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Collection;
import sprite.Sprite;
import updater.Updater;


/**
 * Updates the entire game by calling all other Updaters.
 * 
 * @author Seon Kang
 * 
 */

public class GameHandler {
    private ArrayList<Updater> myUpdaterList = new ArrayList<Updater>();
    private ArrayList<Sprite> mySpriteList = new ArrayList<Sprite>();
    private GameFrame myFrame;
    private Sprite myPlayer;



    /**
     * 
     * @param pen to draw
     */
    public void paint (Graphics pen) {
        for (Sprite s : mySpriteList) {

        }
    }
    
    /**
     * 
     */
    public void update () {
        for (Updater u : myUpdaterList) {
            u.update();
        }
    }

    /**
     * @param s sprite
     * @return whether this sprite hits top or bottom of the canvas
     */
    public boolean isHitTopBottomWall (Sprite s) {
        Dimension canvasSize = getFrame().getCanvasSize();
        return s.getTop() > canvasSize.height || s.getBottom() < 0;
    }

    /**
     * @param s sprite
     * @return whether this sprite hits left or right of the canvas
     */
    public boolean isHitLeftRightWall (Sprite s) {
        Dimension canvasSize = getFrame().getCanvasSize();
        return s.getLeft() < 0 || s.getRight() > canvasSize.width;
    }

    /**
     * Tell the frame that you won.
     */
    public void winGame () {
        getFrame().nextLevel();
    }

    /**
     * Tell the frame that you lost.
     */
    public void loseGame () {
        getFrame().lose();
    }

    /**
     * 
     * @return
     */
    public ArrayList<Sprite> getMySpriteList () {
        return mySpriteList;
    }

    /**
     * 
     * @param collection
     */
    public void setMySpriteList (Collection<Sprite> collection) {
        this.mySpriteList = (ArrayList<Sprite>) collection;
    }

    /**
     * 
     * @return
     */
    public GameFrame getFrame () {
        return myFrame;
    }

    /**
     * 
     * @param frame
     */
    public void setFrame (GameFrame frame) {
        this.myFrame = frame;
    }

    /**
     * 
     * @return
     */
    public Sprite getMyPlayer () {
        return myPlayer;
    }

    /**
     * 
     * @param player 
     */
    public void setMyPlayer (Sprite player) {
        this.myPlayer = player;
    }

    /**
     * @return the key pressed by the player.
     */
    public int getUserKeyInput () {
        return getFrame().getUserKeyInput();
    }

    /**
     * @param up updater to add
     */
    public void addUpdater (Updater up) {
        myUpdaterList.add(up);
    }
}
